{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "GL_pandas_1.ipynb",
      "provenance": [],
      "authorship_tag": "ABX9TyNz16RAtFZHIuvlhZgBgJOC",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/Divyanshu-ISM/Oil-and-Gas-data-analysis/blob/master/GL_pandas_1.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "7YichAOB0iLp",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import pandas as pd\n",
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "import seaborn as sns"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "7v66hEl21gm5",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "df = pd.read_csv('Uber Drives 2016.csv')"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "G8xy7iAi1qV5",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 195
        },
        "outputId": "bc7cd24a-af34-4839-c098-0522cd5c895f"
      },
      "source": [
        "df.head()"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>START_DATE*</th>\n",
              "      <th>END_DATE*</th>\n",
              "      <th>CATEGORY*</th>\n",
              "      <th>START*</th>\n",
              "      <th>STOP*</th>\n",
              "      <th>MILES*</th>\n",
              "      <th>PURPOSE*</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1/1/2016 21:11</td>\n",
              "      <td>1/1/2016 21:17</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>5.1</td>\n",
              "      <td>Meal/Entertain</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>1/2/2016 1:25</td>\n",
              "      <td>1/2/2016 1:37</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>5.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>1/2/2016 20:25</td>\n",
              "      <td>1/2/2016 20:38</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>4.8</td>\n",
              "      <td>Errand/Supplies</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>1/5/2016 17:31</td>\n",
              "      <td>1/5/2016 17:45</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>4.7</td>\n",
              "      <td>Meeting</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>1/6/2016 14:42</td>\n",
              "      <td>1/6/2016 15:49</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>West Palm Beach</td>\n",
              "      <td>63.7</td>\n",
              "      <td>Customer Visit</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "      START_DATE*       END_DATE*  ... MILES*         PURPOSE*\n",
              "0  1/1/2016 21:11  1/1/2016 21:17  ...    5.1   Meal/Entertain\n",
              "1   1/2/2016 1:25   1/2/2016 1:37  ...    5.0              NaN\n",
              "2  1/2/2016 20:25  1/2/2016 20:38  ...    4.8  Errand/Supplies\n",
              "3  1/5/2016 17:31  1/5/2016 17:45  ...    4.7          Meeting\n",
              "4  1/6/2016 14:42  1/6/2016 15:49  ...   63.7   Customer Visit\n",
              "\n",
              "[5 rows x 7 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 65
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "D5CDdWQi2qXY",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "e785298e-a850-4d80-c580-36afa5f75cfa"
      },
      "source": [
        "type(df['STOP*']) #you can see that each column is a series. "
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "pandas.core.series.Series"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 66
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "9K6OnI-U7E4N",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "77356b9f-6484-40fb-c594-b3656498e9bd"
      },
      "source": [
        "# df.head()\n",
        "df.shape"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(1156, 7)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 67
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Gj6D_rFT7mm5",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 195
        },
        "outputId": "f74a181a-3b33-43e3-860d-ee72602fa448"
      },
      "source": [
        "df.tail()"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>START_DATE*</th>\n",
              "      <th>END_DATE*</th>\n",
              "      <th>CATEGORY*</th>\n",
              "      <th>START*</th>\n",
              "      <th>STOP*</th>\n",
              "      <th>MILES*</th>\n",
              "      <th>PURPOSE*</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>1151</th>\n",
              "      <td>12/31/2016 13:24</td>\n",
              "      <td>12/31/2016 13:42</td>\n",
              "      <td>Business</td>\n",
              "      <td>Kar?chi</td>\n",
              "      <td>Unknown Location</td>\n",
              "      <td>3.9</td>\n",
              "      <td>Temporary Site</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1152</th>\n",
              "      <td>12/31/2016 15:03</td>\n",
              "      <td>12/31/2016 15:38</td>\n",
              "      <td>Business</td>\n",
              "      <td>Unknown Location</td>\n",
              "      <td>Unknown Location</td>\n",
              "      <td>16.2</td>\n",
              "      <td>Meeting</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1153</th>\n",
              "      <td>12/31/2016 21:32</td>\n",
              "      <td>12/31/2016 21:50</td>\n",
              "      <td>Business</td>\n",
              "      <td>Katunayake</td>\n",
              "      <td>Gampaha</td>\n",
              "      <td>6.4</td>\n",
              "      <td>Temporary Site</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1154</th>\n",
              "      <td>12/31/2016 22:08</td>\n",
              "      <td>12/31/2016 23:51</td>\n",
              "      <td>Business</td>\n",
              "      <td>Gampaha</td>\n",
              "      <td>Ilukwatta</td>\n",
              "      <td>48.2</td>\n",
              "      <td>Temporary Site</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1155</th>\n",
              "      <td>Totals</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>12204.7</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "           START_DATE*         END_DATE*  ...   MILES*        PURPOSE*\n",
              "1151  12/31/2016 13:24  12/31/2016 13:42  ...      3.9  Temporary Site\n",
              "1152  12/31/2016 15:03  12/31/2016 15:38  ...     16.2         Meeting\n",
              "1153  12/31/2016 21:32  12/31/2016 21:50  ...      6.4  Temporary Site\n",
              "1154  12/31/2016 22:08  12/31/2016 23:51  ...     48.2  Temporary Site\n",
              "1155            Totals               NaN  ...  12204.7             NaN\n",
              "\n",
              "[5 rows x 7 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 68
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "YBNQN_978Azf",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#NaN means not any number. \n",
        "#OFFICIAL Junk character of pandas."
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "yzDKqluS8S1-",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 151
        },
        "outputId": "02bd55cf-9454-49c9-9d5c-b86103222e3d"
      },
      "source": [
        "df.dtypes\n",
        "#so you can see that by default every date that a pandas reads is a string(object).\n",
        "#to make it usable and manipulate-able - we have to convert it into a Date Type object."
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "START_DATE*     object\n",
              "END_DATE*       object\n",
              "CATEGORY*       object\n",
              "START*          object\n",
              "STOP*           object\n",
              "MILES*         float64\n",
              "PURPOSE*        object\n",
              "dtype: object"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 70
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "iMvdNDAX8cky",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "temp = pd.DataFrame({'A':['1','2','3'], 'B':['11', '12', '13'] , 'C':['12-06-2012', '12-07-2012', '13-08-2012']})"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "mHpTT2yGAf21",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 136
        },
        "outputId": "c48e8c94-3102-4b8c-a6eb-63cb535777e4"
      },
      "source": [
        "temp"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>A</th>\n",
              "      <th>B</th>\n",
              "      <th>C</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>11</td>\n",
              "      <td>12-06-2012</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2</td>\n",
              "      <td>12</td>\n",
              "      <td>12-07-2012</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>3</td>\n",
              "      <td>13</td>\n",
              "      <td>13-08-2012</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   A   B           C\n",
              "0  1  11  12-06-2012\n",
              "1  2  12  12-07-2012\n",
              "2  3  13  13-08-2012"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 72
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CO7nFbqhAk5u",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "b0ca241b-d269-4f71-9f61-bbf9d3c2e204"
      },
      "source": [
        "pd.to_datetime('june-2016-2')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Timestamp('2016-06-02 00:00:00')"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 73
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "oYkok8_gA2iE",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "cfa0d8b2-be94-4e1d-8ace-568fffe95466"
      },
      "source": [
        "pd.to_datetime('2-june-2016')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Timestamp('2016-06-02 00:00:00')"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 74
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8eNKky3yA6-1",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# pd.to_datetime('2-2016-06') error. Gets confused what's what"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "fm3Tx-J6CRkf",
        "colab_type": "text"
      },
      "source": [
        "By default the pd.to_datetime expects the Y-M-D format. \n",
        "You can change the format using datetime library's format method."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "fvqliztEBAoB",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "temp['C'] = pd.to_datetime(temp['C'])"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "t57_FNCLDPeJ",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 136
        },
        "outputId": "ee273ef7-8a54-43a7-ea85-42686689d9a3"
      },
      "source": [
        "# type(temp['C'][0]) #pandas._libs.tslibs.timestamps.Timestamp\n",
        "temp"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>A</th>\n",
              "      <th>B</th>\n",
              "      <th>C</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>11</td>\n",
              "      <td>2012-12-06</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2</td>\n",
              "      <td>12</td>\n",
              "      <td>2012-12-07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>3</td>\n",
              "      <td>13</td>\n",
              "      <td>2012-08-13</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   A   B          C\n",
              "0  1  11 2012-12-06\n",
              "1  2  12 2012-12-07\n",
              "2  3  13 2012-08-13"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 77
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6qR3cOUZFB4L",
        "colab_type": "text"
      },
      "source": [
        "#Note- \n",
        "If you want to convert all dates to date-time format and just ignore the few ones that cannot be converted (by writing NaT not any time) you can use - \n",
        "\n",
        "pd.to_datetime(df['datecolumn'] , errors = 'coerce')"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "HBu5ylmHDWnE",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 136
        },
        "outputId": "d2d23f34-faa6-426c-cb3a-32cebb223a6c"
      },
      "source": [
        "temp"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>A</th>\n",
              "      <th>B</th>\n",
              "      <th>C</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>11</td>\n",
              "      <td>2012-12-06</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2</td>\n",
              "      <td>12</td>\n",
              "      <td>2012-12-07</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>3</td>\n",
              "      <td>13</td>\n",
              "      <td>2012-08-13</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   A   B          C\n",
              "0  1  11 2012-12-06\n",
              "1  2  12 2012-12-07\n",
              "2  3  13 2012-08-13"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 78
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "SfHcUvVhFd4Y",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "598ce6e8-b12e-489d-8c25-e331ab67f6e4"
      },
      "source": [
        "# Now here \n",
        "type(temp['A'][0]) #But we want it in numeric form."
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "str"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 79
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "zIKvj013FoJK",
        "colab_type": "text"
      },
      "source": [
        "##pd.to_numeric"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ZuxP8W9CFjQG",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "temp['A'] = pd.to_numeric(temp['A'])"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "QdJ6OQFMFvFI",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "53827b4b-2279-4904-eb68-570d60201b2b"
      },
      "source": [
        "type(temp['A'][0]) ## str-----> numpy.int64 brilliant!"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "numpy.int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 81
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qRYo4-bBGfMx",
        "colab_type": "text"
      },
      "source": [
        "# df['colname'].value_counts()"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ppdK0DadFyCM",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 218
        },
        "outputId": "739ceb14-3ae2-4931-9b36-5c103009c5a5"
      },
      "source": [
        "df['START*'].value_counts() #returns the unique start* points and then finds the # of rows corresponding to each."
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Cary                   201\n",
              "Unknown Location       148\n",
              "Morrisville             85\n",
              "Whitebridge             68\n",
              "Islamabad               57\n",
              "                      ... \n",
              "Fuquay-Varina            1\n",
              "Red River District       1\n",
              "Arabi                    1\n",
              "University District      1\n",
              "Washington               1\n",
              "Name: START*, Length: 177, dtype: int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 82
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "q35246oiGwXL",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 118
        },
        "outputId": "88f158ab-8a1d-4b9a-e73f-cb13952fed21"
      },
      "source": [
        "df['START*'].value_counts().head() #TOP 5 starting points (with the most trips)."
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Cary                201\n",
              "Unknown Location    148\n",
              "Morrisville          85\n",
              "Whitebridge          68\n",
              "Islamabad            57\n",
              "Name: START*, dtype: int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 83
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "WYVkOsoWHHsT",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 118
        },
        "outputId": "dd34e09d-2dd3-4900-a0c4-199abba6cb72"
      },
      "source": [
        "df['START*'].value_counts().tail() #least tripped starting points."
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Fuquay-Varina          1\n",
              "Red River District     1\n",
              "Arabi                  1\n",
              "University District    1\n",
              "Washington             1\n",
              "Name: START*, dtype: int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 84
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qkTPfCADHkDu",
        "colab_type": "text"
      },
      "source": [
        "#Common Data Manipulation Tasks\n",
        "\n",
        "5 Verbs of Data MAnipulation-\n",
        "\n",
        "1. Selecting/Indexing\n",
        "2. Filtering\n",
        "3. Sorting\n",
        "4. Mutating/Conditionally adding columns.\n",
        "5. Groupby/Summarize."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "AErcROUQIYjj",
        "colab_type": "text"
      },
      "source": [
        "Just to Add to this : colname.apply(functions) "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "bFDTHtBVHaLU",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "##### LEt's Practice This #####"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qfOEp4lwJHTk",
        "colab_type": "text"
      },
      "source": [
        "1. Selecting/ Indexing -\n",
        "\n",
        "\n",
        "*   df['column_name']\n",
        "*   df.iloc[0:5 , 1:4]\n",
        "*   df.loc[....]\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "4XnaIiVBJGNf",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 195
        },
        "outputId": "a49b1ed1-adf3-4e75-9ba5-e6b4dbce0a11"
      },
      "source": [
        "df.iloc[0:5 , 0:5]"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>START_DATE*</th>\n",
              "      <th>END_DATE*</th>\n",
              "      <th>CATEGORY*</th>\n",
              "      <th>START*</th>\n",
              "      <th>STOP*</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1/1/2016 21:11</td>\n",
              "      <td>1/1/2016 21:17</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>1/2/2016 1:25</td>\n",
              "      <td>1/2/2016 1:37</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>1/2/2016 20:25</td>\n",
              "      <td>1/2/2016 20:38</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>1/5/2016 17:31</td>\n",
              "      <td>1/5/2016 17:45</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>1/6/2016 14:42</td>\n",
              "      <td>1/6/2016 15:49</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>West Palm Beach</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "      START_DATE*       END_DATE* CATEGORY*       START*            STOP*\n",
              "0  1/1/2016 21:11  1/1/2016 21:17  Business  Fort Pierce      Fort Pierce\n",
              "1   1/2/2016 1:25   1/2/2016 1:37  Business  Fort Pierce      Fort Pierce\n",
              "2  1/2/2016 20:25  1/2/2016 20:38  Business  Fort Pierce      Fort Pierce\n",
              "3  1/5/2016 17:31  1/5/2016 17:45  Business  Fort Pierce      Fort Pierce\n",
              "4  1/6/2016 14:42  1/6/2016 15:49  Business  Fort Pierce  West Palm Beach"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 86
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "XFFsZsbjJu9F",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 195
        },
        "outputId": "478cb99d-2ce5-4286-8f77-cd65fecddbb9"
      },
      "source": [
        "df.iloc[0:5 , [1,2]]"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>END_DATE*</th>\n",
              "      <th>CATEGORY*</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1/1/2016 21:17</td>\n",
              "      <td>Business</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>1/2/2016 1:37</td>\n",
              "      <td>Business</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>1/2/2016 20:38</td>\n",
              "      <td>Business</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>1/5/2016 17:45</td>\n",
              "      <td>Business</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>1/6/2016 15:49</td>\n",
              "      <td>Business</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "        END_DATE* CATEGORY*\n",
              "0  1/1/2016 21:17  Business\n",
              "1   1/2/2016 1:37  Business\n",
              "2  1/2/2016 20:38  Business\n",
              "3  1/5/2016 17:45  Business\n",
              "4  1/6/2016 15:49  Business"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 87
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rz1wH1_2J3Su",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 106
        },
        "outputId": "d6299d95-8d9e-4b51-db17-ff4ab036735b"
      },
      "source": [
        "df.iloc[[1,4], [2,5]]"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>CATEGORY*</th>\n",
              "      <th>MILES*</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Business</td>\n",
              "      <td>5.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Business</td>\n",
              "      <td>63.7</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "  CATEGORY*  MILES*\n",
              "1  Business     5.0\n",
              "4  Business    63.7"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 88
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rvg-uun3J-FB",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 166
        },
        "outputId": "17b176c7-4c01-4d6d-8cda-dadfd9af2223"
      },
      "source": [
        "df.iloc[0:4,:]"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>START_DATE*</th>\n",
              "      <th>END_DATE*</th>\n",
              "      <th>CATEGORY*</th>\n",
              "      <th>START*</th>\n",
              "      <th>STOP*</th>\n",
              "      <th>MILES*</th>\n",
              "      <th>PURPOSE*</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1/1/2016 21:11</td>\n",
              "      <td>1/1/2016 21:17</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>5.1</td>\n",
              "      <td>Meal/Entertain</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>1/2/2016 1:25</td>\n",
              "      <td>1/2/2016 1:37</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>5.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>1/2/2016 20:25</td>\n",
              "      <td>1/2/2016 20:38</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>4.8</td>\n",
              "      <td>Errand/Supplies</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>1/5/2016 17:31</td>\n",
              "      <td>1/5/2016 17:45</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>4.7</td>\n",
              "      <td>Meeting</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "      START_DATE*       END_DATE*  ... MILES*         PURPOSE*\n",
              "0  1/1/2016 21:11  1/1/2016 21:17  ...    5.1   Meal/Entertain\n",
              "1   1/2/2016 1:25   1/2/2016 1:37  ...    5.0              NaN\n",
              "2  1/2/2016 20:25  1/2/2016 20:38  ...    4.8  Errand/Supplies\n",
              "3  1/5/2016 17:31  1/5/2016 17:45  ...    4.7          Meeting\n",
              "\n",
              "[4 rows x 7 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 89
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "DfALvRQuKKqC",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 166
        },
        "outputId": "f6d45cc6-346d-471f-c0f9-f286e008d551"
      },
      "source": [
        "df.iloc[0:4]"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>START_DATE*</th>\n",
              "      <th>END_DATE*</th>\n",
              "      <th>CATEGORY*</th>\n",
              "      <th>START*</th>\n",
              "      <th>STOP*</th>\n",
              "      <th>MILES*</th>\n",
              "      <th>PURPOSE*</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1/1/2016 21:11</td>\n",
              "      <td>1/1/2016 21:17</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>5.1</td>\n",
              "      <td>Meal/Entertain</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>1/2/2016 1:25</td>\n",
              "      <td>1/2/2016 1:37</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>5.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>1/2/2016 20:25</td>\n",
              "      <td>1/2/2016 20:38</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>4.8</td>\n",
              "      <td>Errand/Supplies</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>1/5/2016 17:31</td>\n",
              "      <td>1/5/2016 17:45</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>4.7</td>\n",
              "      <td>Meeting</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "      START_DATE*       END_DATE*  ... MILES*         PURPOSE*\n",
              "0  1/1/2016 21:11  1/1/2016 21:17  ...    5.1   Meal/Entertain\n",
              "1   1/2/2016 1:25   1/2/2016 1:37  ...    5.0              NaN\n",
              "2  1/2/2016 20:25  1/2/2016 20:38  ...    4.8  Errand/Supplies\n",
              "3  1/5/2016 17:31  1/5/2016 17:45  ...    4.7          Meeting\n",
              "\n",
              "[4 rows x 7 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 90
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6nq1U39BMl-u",
        "colab_type": "text"
      },
      "source": [
        "##Filtering Columns\n",
        "\n",
        "*  skeleton for filtering df[ ]\n",
        "*  If you pass it as a string - df['col1'] -> returns a series\n",
        "*  If you pass it as a list - df[['col1']] -> returns a DF"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "FEO-0JjzPIv3",
        "colab_type": "text"
      },
      "source": [
        "##Excercise : Extract 1st 5 rows and START* and MILES* columns"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "WnoMfTCYKPq3",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 195
        },
        "outputId": "e31204ec-69a3-44ce-f6bd-0b1059cc437f"
      },
      "source": [
        "df.loc[0:4 , ['START*','MILES*']] #could have done .head() but this what I have done is standard practice. \n",
        "\n",
        "#df.loc[0:4] -> Both 0 and 4 are included."
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>START*</th>\n",
              "      <th>MILES*</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>5.1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>5.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>4.8</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>4.7</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>63.7</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "        START*  MILES*\n",
              "0  Fort Pierce     5.1\n",
              "1  Fort Pierce     5.0\n",
              "2  Fort Pierce     4.8\n",
              "3  Fort Pierce     4.7\n",
              "4  Fort Pierce    63.7"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 91
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "GWRaD8JqPY9u",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 195
        },
        "outputId": "fe4201f7-6864-4c8d-c204-a29815199425"
      },
      "source": [
        "# df.iloc[0:4 , [3,5]] #iloc doesn't include the last row in 0:4. so we gotta provide one extra. \n",
        "df.iloc[0:5 , [3,5]]"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>START*</th>\n",
              "      <th>MILES*</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>5.1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>5.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>4.8</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>4.7</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>63.7</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "        START*  MILES*\n",
              "0  Fort Pierce     5.1\n",
              "1  Fort Pierce     5.0\n",
              "2  Fort Pierce     4.8\n",
              "3  Fort Pierce     4.7\n",
              "4  Fort Pierce    63.7"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 92
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Z3_L9vLqQNCQ",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "my_rides =df.loc[df['START*'].isin(['Cary','Morrisville'])]"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CkQulTt-T_aO",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 402
        },
        "outputId": "70f1d736-0fc9-4af9-9412-b67b70b31820"
      },
      "source": [
        "my_rides.head(n=10) #you can see that the indices are not updated. \n",
        "\n",
        "my_rides.reset_index()"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>index</th>\n",
              "      <th>START_DATE*</th>\n",
              "      <th>END_DATE*</th>\n",
              "      <th>CATEGORY*</th>\n",
              "      <th>START*</th>\n",
              "      <th>STOP*</th>\n",
              "      <th>MILES*</th>\n",
              "      <th>PURPOSE*</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>7</td>\n",
              "      <td>1/7/2016 13:27</td>\n",
              "      <td>1/7/2016 13:33</td>\n",
              "      <td>Business</td>\n",
              "      <td>Cary</td>\n",
              "      <td>Cary</td>\n",
              "      <td>0.8</td>\n",
              "      <td>Meeting</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>8</td>\n",
              "      <td>1/10/2016 8:05</td>\n",
              "      <td>1/10/2016 8:25</td>\n",
              "      <td>Business</td>\n",
              "      <td>Cary</td>\n",
              "      <td>Morrisville</td>\n",
              "      <td>8.3</td>\n",
              "      <td>Meeting</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>27</td>\n",
              "      <td>1/15/2016 0:41</td>\n",
              "      <td>1/15/2016 1:01</td>\n",
              "      <td>Business</td>\n",
              "      <td>Morrisville</td>\n",
              "      <td>Cary</td>\n",
              "      <td>8.0</td>\n",
              "      <td>Errand/Supplies</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>28</td>\n",
              "      <td>1/15/2016 11:43</td>\n",
              "      <td>1/15/2016 12:03</td>\n",
              "      <td>Business</td>\n",
              "      <td>Cary</td>\n",
              "      <td>Durham</td>\n",
              "      <td>10.4</td>\n",
              "      <td>Meal/Entertain</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>30</td>\n",
              "      <td>1/18/2016 14:55</td>\n",
              "      <td>1/18/2016 15:06</td>\n",
              "      <td>Business</td>\n",
              "      <td>Cary</td>\n",
              "      <td>Cary</td>\n",
              "      <td>4.8</td>\n",
              "      <td>Meal/Entertain</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>281</th>\n",
              "      <td>1050</td>\n",
              "      <td>12/14/2016 16:52</td>\n",
              "      <td>12/14/2016 17:10</td>\n",
              "      <td>Business</td>\n",
              "      <td>Cary</td>\n",
              "      <td>Cary</td>\n",
              "      <td>3.4</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>282</th>\n",
              "      <td>1051</td>\n",
              "      <td>12/14/2016 17:22</td>\n",
              "      <td>12/14/2016 17:34</td>\n",
              "      <td>Business</td>\n",
              "      <td>Cary</td>\n",
              "      <td>Cary</td>\n",
              "      <td>3.3</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>283</th>\n",
              "      <td>1052</td>\n",
              "      <td>12/14/2016 17:50</td>\n",
              "      <td>12/14/2016 18:00</td>\n",
              "      <td>Business</td>\n",
              "      <td>Cary</td>\n",
              "      <td>Morrisville</td>\n",
              "      <td>3.0</td>\n",
              "      <td>Meal/Entertain</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>284</th>\n",
              "      <td>1053</td>\n",
              "      <td>12/14/2016 20:24</td>\n",
              "      <td>12/14/2016 20:40</td>\n",
              "      <td>Business</td>\n",
              "      <td>Morrisville</td>\n",
              "      <td>Cary</td>\n",
              "      <td>3.1</td>\n",
              "      <td>Customer Visit</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>285</th>\n",
              "      <td>1054</td>\n",
              "      <td>12/15/2016 14:20</td>\n",
              "      <td>12/15/2016 14:54</td>\n",
              "      <td>Business</td>\n",
              "      <td>Cary</td>\n",
              "      <td>Morrisville</td>\n",
              "      <td>10.6</td>\n",
              "      <td>Meeting</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>286 rows × 8 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "     index       START_DATE*  ... MILES*         PURPOSE*\n",
              "0        7    1/7/2016 13:27  ...    0.8          Meeting\n",
              "1        8    1/10/2016 8:05  ...    8.3          Meeting\n",
              "2       27    1/15/2016 0:41  ...    8.0  Errand/Supplies\n",
              "3       28   1/15/2016 11:43  ...   10.4   Meal/Entertain\n",
              "4       30   1/18/2016 14:55  ...    4.8   Meal/Entertain\n",
              "..     ...               ...  ...    ...              ...\n",
              "281   1050  12/14/2016 16:52  ...    3.4              NaN\n",
              "282   1051  12/14/2016 17:22  ...    3.3              NaN\n",
              "283   1052  12/14/2016 17:50  ...    3.0   Meal/Entertain\n",
              "284   1053  12/14/2016 20:24  ...    3.1   Customer Visit\n",
              "285   1054  12/15/2016 14:20  ...   10.6          Meeting\n",
              "\n",
              "[286 rows x 8 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 94
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "q2q01d1xWFnD",
        "colab_type": "text"
      },
      "source": [
        "#FILTERING\n",
        "\n",
        "Q. Find all trips with distance > 10 miles and originating from Carry and Morrisville."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "mRFeDjRuVBE8",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 195
        },
        "outputId": "719152de-45e1-4168-d521-33f497482844"
      },
      "source": [
        "# df.head()\n",
        "q1 = df[(df['MILES*']>10.0) & (df['START*'].isin(['Cary','Morrisville']))]\n",
        "q1.head()"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>START_DATE*</th>\n",
              "      <th>END_DATE*</th>\n",
              "      <th>CATEGORY*</th>\n",
              "      <th>START*</th>\n",
              "      <th>STOP*</th>\n",
              "      <th>MILES*</th>\n",
              "      <th>PURPOSE*</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>28</th>\n",
              "      <td>1/15/2016 11:43</td>\n",
              "      <td>1/15/2016 12:03</td>\n",
              "      <td>Business</td>\n",
              "      <td>Cary</td>\n",
              "      <td>Durham</td>\n",
              "      <td>10.4</td>\n",
              "      <td>Meal/Entertain</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>34</th>\n",
              "      <td>1/20/2016 10:36</td>\n",
              "      <td>1/20/2016 11:11</td>\n",
              "      <td>Business</td>\n",
              "      <td>Cary</td>\n",
              "      <td>Raleigh</td>\n",
              "      <td>17.1</td>\n",
              "      <td>Meeting</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>46</th>\n",
              "      <td>1/27/2016 10:19</td>\n",
              "      <td>1/27/2016 10:48</td>\n",
              "      <td>Business</td>\n",
              "      <td>Cary</td>\n",
              "      <td>Raleigh</td>\n",
              "      <td>18.7</td>\n",
              "      <td>Customer Visit</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>50</th>\n",
              "      <td>1/28/2016 12:28</td>\n",
              "      <td>1/28/2016 13:00</td>\n",
              "      <td>Business</td>\n",
              "      <td>Cary</td>\n",
              "      <td>Raleigh</td>\n",
              "      <td>19.0</td>\n",
              "      <td>Temporary Site</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>55</th>\n",
              "      <td>1/29/2016 11:43</td>\n",
              "      <td>1/29/2016 12:03</td>\n",
              "      <td>Business</td>\n",
              "      <td>Cary</td>\n",
              "      <td>Durham</td>\n",
              "      <td>10.4</td>\n",
              "      <td>Meeting</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "        START_DATE*        END_DATE* CATEGORY*  ...    STOP* MILES*        PURPOSE*\n",
              "28  1/15/2016 11:43  1/15/2016 12:03  Business  ...   Durham   10.4  Meal/Entertain\n",
              "34  1/20/2016 10:36  1/20/2016 11:11  Business  ...  Raleigh   17.1         Meeting\n",
              "46  1/27/2016 10:19  1/27/2016 10:48  Business  ...  Raleigh   18.7  Customer Visit\n",
              "50  1/28/2016 12:28  1/28/2016 13:00  Business  ...  Raleigh   19.0  Temporary Site\n",
              "55  1/29/2016 11:43  1/29/2016 12:03  Business  ...   Durham   10.4         Meeting\n",
              "\n",
              "[5 rows x 7 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 95
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "dW1qNsT3WXOv",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "q1.reset_index(inplace=True)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "KghS6UoErPez",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "q1=q1.drop('index',axis=1)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Ks2qk7eWrX7G",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 136
        },
        "outputId": "2a660c69-82b7-4240-907e-9545b199e21e"
      },
      "source": [
        "q1.head(3)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>START_DATE*</th>\n",
              "      <th>END_DATE*</th>\n",
              "      <th>CATEGORY*</th>\n",
              "      <th>START*</th>\n",
              "      <th>STOP*</th>\n",
              "      <th>MILES*</th>\n",
              "      <th>PURPOSE*</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1/15/2016 11:43</td>\n",
              "      <td>1/15/2016 12:03</td>\n",
              "      <td>Business</td>\n",
              "      <td>Cary</td>\n",
              "      <td>Durham</td>\n",
              "      <td>10.4</td>\n",
              "      <td>Meal/Entertain</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>1/20/2016 10:36</td>\n",
              "      <td>1/20/2016 11:11</td>\n",
              "      <td>Business</td>\n",
              "      <td>Cary</td>\n",
              "      <td>Raleigh</td>\n",
              "      <td>17.1</td>\n",
              "      <td>Meeting</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>1/27/2016 10:19</td>\n",
              "      <td>1/27/2016 10:48</td>\n",
              "      <td>Business</td>\n",
              "      <td>Cary</td>\n",
              "      <td>Raleigh</td>\n",
              "      <td>18.7</td>\n",
              "      <td>Customer Visit</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "       START_DATE*        END_DATE* CATEGORY*  ...    STOP* MILES*        PURPOSE*\n",
              "0  1/15/2016 11:43  1/15/2016 12:03  Business  ...   Durham   10.4  Meal/Entertain\n",
              "1  1/20/2016 10:36  1/20/2016 11:11  Business  ...  Raleigh   17.1         Meeting\n",
              "2  1/27/2016 10:19  1/27/2016 10:48  Business  ...  Raleigh   18.7  Customer Visit\n",
              "\n",
              "[3 rows x 7 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 104
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "R2tugjeZr0RB",
        "colab_type": "text"
      },
      "source": [
        "#Sorting"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Un5JHbm8r_gi",
        "colab_type": "text"
      },
      "source": [
        "1. Sorting by single column."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Kv2Voecxrnww",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 195
        },
        "outputId": "cf6aa468-581f-4ac4-81ad-12235f3bb67e"
      },
      "source": [
        "df.sort_values(by='MILES*',ascending=False).head()"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>START_DATE*</th>\n",
              "      <th>END_DATE*</th>\n",
              "      <th>CATEGORY*</th>\n",
              "      <th>START*</th>\n",
              "      <th>STOP*</th>\n",
              "      <th>MILES*</th>\n",
              "      <th>PURPOSE*</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>1155</th>\n",
              "      <td>Totals</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>12204.7</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>269</th>\n",
              "      <td>3/25/2016 16:52</td>\n",
              "      <td>3/25/2016 22:22</td>\n",
              "      <td>Business</td>\n",
              "      <td>Latta</td>\n",
              "      <td>Jacksonville</td>\n",
              "      <td>310.3</td>\n",
              "      <td>Customer Visit</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>270</th>\n",
              "      <td>3/25/2016 22:54</td>\n",
              "      <td>3/26/2016 1:39</td>\n",
              "      <td>Business</td>\n",
              "      <td>Jacksonville</td>\n",
              "      <td>Kissimmee</td>\n",
              "      <td>201.0</td>\n",
              "      <td>Meeting</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>881</th>\n",
              "      <td>10/30/2016 15:22</td>\n",
              "      <td>10/30/2016 18:23</td>\n",
              "      <td>Business</td>\n",
              "      <td>Asheville</td>\n",
              "      <td>Mebane</td>\n",
              "      <td>195.9</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>776</th>\n",
              "      <td>9/27/2016 21:01</td>\n",
              "      <td>9/28/2016 2:37</td>\n",
              "      <td>Business</td>\n",
              "      <td>Unknown Location</td>\n",
              "      <td>Unknown Location</td>\n",
              "      <td>195.6</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "           START_DATE*         END_DATE*  ...   MILES*        PURPOSE*\n",
              "1155            Totals               NaN  ...  12204.7             NaN\n",
              "269    3/25/2016 16:52   3/25/2016 22:22  ...    310.3  Customer Visit\n",
              "270    3/25/2016 22:54    3/26/2016 1:39  ...    201.0         Meeting\n",
              "881   10/30/2016 15:22  10/30/2016 18:23  ...    195.9             NaN\n",
              "776    9/27/2016 21:01    9/28/2016 2:37  ...    195.6             NaN\n",
              "\n",
              "[5 rows x 7 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 106
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "iV0riQl7sUpo",
        "colab_type": "text"
      },
      "source": [
        "2. Sorting by multiple columns."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Lk_cs0MusLw-",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 195
        },
        "outputId": "869175d4-a4e5-46a3-f260-f0e16a19c903"
      },
      "source": [
        "df.sort_values(by=['START*','MILES*'],ascending=[True,False]).head()"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>START_DATE*</th>\n",
              "      <th>END_DATE*</th>\n",
              "      <th>CATEGORY*</th>\n",
              "      <th>START*</th>\n",
              "      <th>STOP*</th>\n",
              "      <th>MILES*</th>\n",
              "      <th>PURPOSE*</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>906</th>\n",
              "      <td>11/4/2016 21:04</td>\n",
              "      <td>11/4/2016 21:20</td>\n",
              "      <td>Business</td>\n",
              "      <td>Agnew</td>\n",
              "      <td>Cory</td>\n",
              "      <td>4.3</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>911</th>\n",
              "      <td>11/6/2016 10:50</td>\n",
              "      <td>11/6/2016 11:04</td>\n",
              "      <td>Business</td>\n",
              "      <td>Agnew</td>\n",
              "      <td>Renaissance</td>\n",
              "      <td>2.4</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>908</th>\n",
              "      <td>11/5/2016 8:34</td>\n",
              "      <td>11/5/2016 8:43</td>\n",
              "      <td>Business</td>\n",
              "      <td>Agnew</td>\n",
              "      <td>Renaissance</td>\n",
              "      <td>2.2</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>910</th>\n",
              "      <td>11/5/2016 19:20</td>\n",
              "      <td>11/5/2016 19:28</td>\n",
              "      <td>Business</td>\n",
              "      <td>Agnew</td>\n",
              "      <td>Agnew</td>\n",
              "      <td>2.2</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>879</th>\n",
              "      <td>10/30/2016 12:58</td>\n",
              "      <td>10/30/2016 13:18</td>\n",
              "      <td>Business</td>\n",
              "      <td>Almond</td>\n",
              "      <td>Bryson City</td>\n",
              "      <td>15.2</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "          START_DATE*         END_DATE* CATEGORY*  ...        STOP* MILES*  PURPOSE*\n",
              "906   11/4/2016 21:04   11/4/2016 21:20  Business  ...         Cory    4.3       NaN\n",
              "911   11/6/2016 10:50   11/6/2016 11:04  Business  ...  Renaissance    2.4       NaN\n",
              "908    11/5/2016 8:34    11/5/2016 8:43  Business  ...  Renaissance    2.2       NaN\n",
              "910   11/5/2016 19:20   11/5/2016 19:28  Business  ...        Agnew    2.2       NaN\n",
              "879  10/30/2016 12:58  10/30/2016 13:18  Business  ...  Bryson City   15.2       NaN\n",
              "\n",
              "[5 rows x 7 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 109
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "0-mwsL2qtyyM",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "sSAnYtYHuH4T",
        "colab_type": "text"
      },
      "source": [
        "#Conditionally adding columns."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-Zil6UtEuTvW",
        "colab_type": "text"
      },
      "source": [
        "What if Miles >5 is a long trip and <5 is a short trip.\n",
        "\n",
        "So we'll add a Miles-tag column"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "i3P5Jzt0uK0a",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "tag = lambda mile : 'Long' if mile>5.0 else 'Short'"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MHoy6Sl2vZeu",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "df['Mile-Tag'] = df['MILES*'].apply(tag)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rlKcU7Ruvl3V",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 195
        },
        "outputId": "37281f1c-1d11-4771-d873-3fa4e7431f86"
      },
      "source": [
        "df.head()"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>START_DATE*</th>\n",
              "      <th>END_DATE*</th>\n",
              "      <th>CATEGORY*</th>\n",
              "      <th>START*</th>\n",
              "      <th>STOP*</th>\n",
              "      <th>MILES*</th>\n",
              "      <th>PURPOSE*</th>\n",
              "      <th>Mile-Tag</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1/1/2016 21:11</td>\n",
              "      <td>1/1/2016 21:17</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>5.1</td>\n",
              "      <td>Meal/Entertain</td>\n",
              "      <td>Long</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>1/2/2016 1:25</td>\n",
              "      <td>1/2/2016 1:37</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>5.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>Short</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>1/2/2016 20:25</td>\n",
              "      <td>1/2/2016 20:38</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>4.8</td>\n",
              "      <td>Errand/Supplies</td>\n",
              "      <td>Short</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>1/5/2016 17:31</td>\n",
              "      <td>1/5/2016 17:45</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>4.7</td>\n",
              "      <td>Meeting</td>\n",
              "      <td>Short</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>1/6/2016 14:42</td>\n",
              "      <td>1/6/2016 15:49</td>\n",
              "      <td>Business</td>\n",
              "      <td>Fort Pierce</td>\n",
              "      <td>West Palm Beach</td>\n",
              "      <td>63.7</td>\n",
              "      <td>Customer Visit</td>\n",
              "      <td>Long</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "      START_DATE*       END_DATE* CATEGORY*  ... MILES*         PURPOSE*  Mile-Tag\n",
              "0  1/1/2016 21:11  1/1/2016 21:17  Business  ...    5.1   Meal/Entertain      Long\n",
              "1   1/2/2016 1:25   1/2/2016 1:37  Business  ...    5.0              NaN     Short\n",
              "2  1/2/2016 20:25  1/2/2016 20:38  Business  ...    4.8  Errand/Supplies     Short\n",
              "3  1/5/2016 17:31  1/5/2016 17:45  Business  ...    4.7          Meeting     Short\n",
              "4  1/6/2016 14:42  1/6/2016 15:49  Business  ...   63.7   Customer Visit      Long\n",
              "\n",
              "[5 rows x 8 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 113
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "DTatnjbYvptD",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 67
        },
        "outputId": "31300827-3020-483b-e27b-5fe4d002e67f"
      },
      "source": [
        "df['Mile-Tag'].value_counts() #very nice way to summarize long and short trip Nos. "
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Long     654\n",
              "Short    502\n",
              "Name: Mile-Tag, dtype: int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 114
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rSQhD4XMv9Ix",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#Let's rather create 3 tags. \n",
        "#1. <5 - Short | 5-10 Medium | >10 Long"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Z8ASUtxIwQk0",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "tagger = lambda mile : "
      ],
      "execution_count": null,
      "outputs": []
    }
  ]
}